package com.tbit.uqbike.webmanager.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tbit.uqbike.annos.OperateLog;
import com.tbit.common.constant.MethodEnum;
import com.tbit.common.constant.ModuleEnum;
import com.tbit.uqbike.object.pojo.AccountDiscount;
import com.tbit.common.entity.view.Result;
import com.tbit.uqbike.service.business.AccountDiscountService;
import com.tbit.utils.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 认证折扣配置
 *
 * @Author:BUGTian
 * @DATE: 2022/9/22
 */
@RestController
@RequestMapping("/accountDiscount")
public class AccountDiscountController {

    @Autowired
    private AccountDiscountService accountDiscountService;

    /**
     * 查询
     *
     * @param adAccountId 区域id
     * @return
     */
    @GetMapping("/query")
    public Result<List<AccountDiscount>> query(Integer adAccountId) {
        Assert.notNull(adAccountId, "区域id不能为空");
        return Result.success(accountDiscountService.queryByAdAccountId(adAccountId));
    }

    /**
     * 新增
     *
     * @param accountDiscount
     * @return
     */
    @PostMapping("/insert")
    @OperateLog(module = ModuleEnum.DISCOUNTCONFIG, methods = MethodEnum.DISCOUNTCONFIG_ADD)
    public Result insert(@RequestBody AccountDiscount accountDiscount) {
        return accountDiscountService.insert(accountDiscount);
    }

    /**
     * 修改
     *
     * @param accountDiscount
     * @return
     */
    @PutMapping("/update")
    @OperateLog(module = ModuleEnum.DISCOUNTCONFIG, methods = MethodEnum.DISCOUNTCONFIG_UPDATE)
    public Result update(@RequestBody AccountDiscount accountDiscount) {
        return accountDiscountService.updateAccountDiscount(accountDiscount);
    }

    /**
     * 删除
     *
     * @param adAccountId 区域id
     * @param configId    配置id
     * @return
     */
    @DeleteMapping("/delete")
    @OperateLog(module = ModuleEnum.DISCOUNTCONFIG, methods = MethodEnum.DISCOUNTCONFIG_DEL)
    public Result delete(Integer adAccountId, Integer configId) {
        Assert.notNulls("参数有误", adAccountId, configId);
        accountDiscountService.remove(new QueryWrapper<AccountDiscount>().eq("adAccountId", adAccountId).eq("configId", configId));
        return Result.success();
    }


}
